var gulp = require("gulp");
var rename = require("gulp-rename");
var iconfont = require('gulp-iconfont');
var consolidate = require('gulp-consolidate');
var del = require('del');

var fontName = 'myfont'; // set name of your symbol font
var template = 'font-style'; // you can also choose 'foundation-style'
//var runTimestamp = Math.round(new Date().getTime());
 
gulp.task('icon', function(){
	return gulp.src(['src/icons/*.svg'])
    .pipe(iconfont({
      normalize: true,
      fontName: fontName, // required 
			prependUnicode: true, // recommended option 
      formats: ['woff'], // default, 'woff2' and 'svg' are available 
      //timestamp: runTimestamp, // recommended to get consistent builds when watching files 
    }))
    .on('glyphs', function(glyphs) {
      var options = {
        glyphs: glyphs.map(function(glyph) {
          // this line is needed because gulp-iconfont has changed the api from 2.0
          return { name: glyph.name, codepoint: glyph.unicode[0].charCodeAt(0) }
        }),
        fontName: fontName,
        fontPath: '../fonts/', // set path to font (from your CSS file if relative)
        className: 'ic' // set class name in your CSS
      };

			gulp.src('src/templates/' + template + '.styl')
        .pipe(consolidate('lodash', options))
        .pipe(rename({ basename:fontName }))
				.pipe(gulp.dest('src/ui-components/iconFont/icons/css/')); // set path to export your CSS
    })
		.pipe(gulp.dest('src/ui-components/iconFont/icons/fonts/'));
});

gulp.task('clean', function() {
  del(
		['src/ui-components/iconFont/icons']
  );
});

gulp.task('default', ['clean', 'icon']);
